package com.spring.schedule_system.dengxiaojiao.appService;


import com.spring.schedule_system.dengxiaojiao.request.DeliverySetDomainIn;
import com.spring.schedule_system.dengxiaojiao.request.DeliverySetDomainOut;
import com.spring.schedule_system.dengxiaojiao.request.DeliverySetDto;
import com.spring.schedule_system.dengxiaojiao.request.DeliverySetQry;
import com.spring.schedule_system.dengxiaojiao.request.DeliverySetRequest;
import com.spring.schedule_system.dengxiaojiao.request.DeliverySetSaveDomainIn;
import com.spring.schedule_system.dengxiaojiao.request.VenDbDeliverySet;
import com.spring.schedule_system.dengxiaojiao.service.DeliverySetService;
import com.spring.schedule_system.dengxiaojiao.util.BizException;
import com.spring.schedule_system.dengxiaojiao.util.ListResult;
import com.spring.schedule_system.dengxiaojiao.util.LyListResultUtil;
import com.spring.schedule_system.dengxiaojiao.util.LyObjectUtil;
import com.spring.schedule_system.dengxiaojiao.util.OptResult;
import com.spring.schedule_system.dengxiaojiao.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/***********************************************************************************************************************
* <p>
    * 预交车天数设置 逻辑biz层
    * </p>
* @author        ly-dengxiaojiao
* @date          2023-03-26
* @version       V1.0
**********************************************************************************************************************/
@Service
public class DeliverySetAppService {
    @Autowired
    DeliverySetService deliverySetService;

    @Transactional
    public OptResult venDbCarDeliveryDaySetSave(DeliverySetRequest deliverySetRequest){
        DeliverySetSaveDomainIn deliverySetSaveDomainIn = LyObjectUtil.convertToByJSON(deliverySetRequest, DeliverySetSaveDomainIn.class);
        List<VenDbDeliverySet> saveDatas = deliverySetSaveDomainIn.getSaveDatas();
        if (StringUtil.IsEmptyOrNull(saveDatas) || (!StringUtil.IsEmptyOrNull(saveDatas) && saveDatas.size() <= 0)) {
            throw BizException.newBizException("500", "请选择操作数据！");
        }
        if (!"batchSame".equals(deliverySetRequest.getModifyType()) && !"allSame".equals(deliverySetRequest.getModifyType())) {
            throw BizException.newBizException("500", "batchSame批量同步，allSame全部同步");
        }
        OptResult optResult = deliverySetService.venDbCarDeliveryDaySetSave(deliverySetSaveDomainIn);
        return optResult;
    }

    public ListResult<DeliverySetDto> venDbCarDeliveryDaySetQuery(DeliverySetQry deliverySetQry){
        DeliverySetDomainIn deliverySetDomainIn = new DeliverySetDomainIn();
        BeanUtils.copyProperties(deliverySetQry, deliverySetDomainIn);
        ListResult<DeliverySetDomainOut> result = deliverySetService.venDbCarDeliveryDaySetQuery(deliverySetDomainIn);
        return LyListResultUtil.convertTo(result, DeliverySetDto.class);
    }


}
